package com.code.view.listeners;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;


/**
 * 生成代码选择器选择事件
 *
 *
 * @author 朱国军
 * @version 2015年3月13日 朱国军
 */
public class RadioGroupSelectListener implements SelectionListener {
    private Button allCheckButton;
    private Button commonCheckButton;
    private Button entityCheckButton;
    private Button serviceCheckButton;
    private Button pageCheckButton;
    private Button controllerCheckButton;


    /**
     * 构造函数
     *
     * @param allCheckButton 全选按钮
     * @param commonCheckButton common包选择按钮
     * @param entityCheckButton 实体和sqlmapper选择按钮
     * @param serviceCheckButton dao和service选择按钮
     * @param pageCheckButton 生成列表和编辑页面选择按钮
     * @param controllerCheckButton 生成controller选择按钮
     */
    public RadioGroupSelectListener(Button allCheckButton, Button commonCheckButton, Button entityCheckButton, Button serviceCheckButton,
            Button pageCheckButton, Button controllerCheckButton) {
        this.allCheckButton = allCheckButton;
        this.commonCheckButton = commonCheckButton;
        this.entityCheckButton = entityCheckButton;
        this.serviceCheckButton = serviceCheckButton;
        this.pageCheckButton = pageCheckButton;
        this.controllerCheckButton = controllerCheckButton;

    }


    @Override
    public void widgetSelected(SelectionEvent e) {
        if (e.getSource().equals(allCheckButton)) {
            if (allCheckButton.getSelection()) {
                commonCheckButton.setSelection(true);
                entityCheckButton.setSelection(true);
                serviceCheckButton.setSelection(true);
                pageCheckButton.setSelection(true);
                serviceCheckButton.setSelection(true);
            } else {
                commonCheckButton.setSelection(false);
                entityCheckButton.setSelection(false);
                serviceCheckButton.setSelection(false);
                pageCheckButton.setSelection(false);
                controllerCheckButton.setSelection(false);
            }
        } else {
            if (commonCheckButton.getSelection() && entityCheckButton.getSelection() && serviceCheckButton.getSelection()
                    && pageCheckButton.getSelection() && controllerCheckButton.getSelection()) {
                allCheckButton.setSelection(true);
            } else {
                allCheckButton.setSelection(false);
            }
        }
    }


    @Override
    public void widgetDefaultSelected(SelectionEvent e) {
        // TODO 自动生成方法存根注释，方法实现时请删除此注释

    }

}
